package com.huawei.crm.sample.infrastructure.outbound.persistence.product.repository.impl;

import com.huawei.crm.sample.domain.product.model.aggragate.Product;
import com.huawei.crm.sample.domain.product.repository.ProductRepository;
import com.huawei.crm.sample.infrastructure.outbound.persistence.product.converter.ProductPOConverter;
import com.huawei.crm.sample.infrastructure.outbound.persistence.product.dao.ProductDAO;
import com.huawei.crm.sample.infrastructure.outbound.persistence.product.po.ProductPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ProductRepositoryImpl implements ProductRepository {
    @Autowired
    private ProductDAO productDAO;
    @Autowired
    private ProductPOConverter productPOConverter;

    @Override
    public void save(Product product) {
        ProductPO po = productPOConverter.toPO(product);
        productDAO.save(po);
    }

    @Override
    public Product findById(String productId) {
        ProductPO po = productDAO.getById(productId);
        return productPOConverter.toDomain(po);
    }

    @Override
    public void update(Product product) {
        ProductPO po = productPOConverter.toPO(product);
        productDAO.updateById(po);
    }
} 